<template>
  <map id="map" latitude="{{latitude}}" longitude="{{longitude}}" scale="15" style="width: 100%; height: 100%" enable-3D="true" show-compass="true" show-scale="true"></map>
</template>

<script>
export default {
  props: {
    latitude: {
      type: Object,
      default: 0
    },
    longitude: {
      type: Object,
      default: 0
    },
    markers: {
      type: Array,
      default: []
    }
  },
  methods: {
    // 在父组件调用的方法，拿到数据传递子组件
    getLocation() {
      wx.getLocation({
        type: 'wgs84',
        success: (res) => {
          this.setData({
            latitude: res.latitude,
            longitude: res.longitude,
            markers: [
              {
                id: 1,
                latitude: res.latitude,
                longitude: res.longitude,
                iconPath: '/images/location.png', // 自定义图标路径
                width: 50,
                height: 50
              }
            ]
          });
        },
        fail: (err) => {
          console.error('Failed to get location:', err);
        }
      });
    }
  }
};
</script>

<style></style>